package com.ruoyi.door.utils;

import com.ruoyi.door.controller.admin.orderinfo.vo.DoorOrderExportVO;
import com.ruoyi.door.domain.DoorOrder;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 订单导出转换工具类
 *
 * @author ruoyi
 */
public class DoorOrderExportConverter {

    /**
     * 转换单个订单对象
     *
     * @param doorOrder 订单对象
     * @return 导出VO
     */
    public static DoorOrderExportVO convert(DoorOrder doorOrder) {
        if (doorOrder == null) {
            return null;
        }

        DoorOrderExportVO exportVO = new DoorOrderExportVO();
        exportVO.setOrderNo(doorOrder.getOrderNo());
        exportVO.setTypeText(convertOrderType(doorOrder.getType()));
        exportVO.setOrderStatusText(convertOrderStatus(doorOrder.getOrderStatus()));
        exportVO.setTotalPrice(doorOrder.getTotalPrice());
        exportVO.setChName(doorOrder.getChName());
        exportVO.setChIdNo(doorOrder.getChIdNo());
        exportVO.setChMobile(doorOrder.getChMobile());
        exportVO.setPayChannelText(convertPayChannel(doorOrder.getPayChannel()));
        exportVO.setCreateTime(doorOrder.getCreateTime());
        exportVO.setPayTime(doorOrder.getPayTime());
        exportVO.setTradeNo(doorOrder.getTradeNo());
        exportVO.setRemark(doorOrder.getRemark());
        exportVO.setRefundCreateTime(doorOrder.getRefundCreateTime());
        exportVO.setRefundTime(doorOrder.getRefundTime());

        return exportVO;
    }

    /**
     * 批量转换订单对象
     *
     * @param doorOrders 订单列表
     * @return 导出VO列表
     */
    public static List<DoorOrderExportVO> convertList(List<DoorOrder> doorOrders) {
        if (doorOrders == null || doorOrders.isEmpty()) {
            return null;
        }

        return doorOrders.stream()
                .map(DoorOrderExportConverter::convert)
                .collect(Collectors.toList());
    }

    /**
     * 转换订单类型
     *
     * @param type 订单类型
     * @return 订单类型文本
     */
    private static String convertOrderType(Long type) {
        if (type == null) {
            return "";
        }

        switch (type.intValue()) {
            case 1:
                return "运维费";
            case 2:
                return "买卡";
            case 3:
                return "人脸";
            default:
                return "未知";
        }
    }

    /**
     * 转换订单状态
     *
     * @param orderStatus 订单状态
     * @return 订单状态文本
     */
    private static String convertOrderStatus(Long orderStatus) {
        if (orderStatus == null) {
            return "";
        }

        switch (orderStatus.intValue()) {
            case 0:
                return "待付款";
            case 1:
                return "已付款";
            case 2:
                return "退款中";
            case 3:
                return "已退款";
            default:
                return "未知";
        }
    }

    /**
     * 转换支付渠道
     *
     * @param payChannel 支付渠道
     * @return 支付渠道文本
     */
    private static String convertPayChannel(String payChannel) {
        if (payChannel == null || payChannel.trim().isEmpty()) {
            return "";
        }

        switch (payChannel) {
            case "1":
                return "微信支付";
            case "2":
                return "银行卡支付";
            default:
                return "其他";
        }
    }
}
